import type Editor from '../../editor'
import { InsertTextOperation } from "../../operations";
import type Operation from '../../operations/operation';
let isBoolean:boolean = false;
let apply:Function = () =>{};
export default function withUpperCase (editor:Editor,target:HTMLElement) {
    if(!isBoolean){
        apply = editor.apply.bind(editor)
        editor.apply = (operation : Operation) => {
            if (operation instanceof InsertTextOperation) {
                let text = operation.getText().toUpperCase();
                operation.setText(text)
            }
            apply(operation)
        }
        target.innerHTML = '关闭大小写'
    }else{
        editor.apply = apply.bind(editor)
        target.innerHTML = '开启大小写'
    }
    isBoolean = !isBoolean
}